
function [LIP] = computeLIPSum( d, c )

alpha_0 = 1;
beta_0 = 1;
nT = size(d,1) - alpha_0 - beta_0;

LIP = zeros(nT + 1 , length(c));
Coeff = zeros(1, length(c));

window = 2;

phi = d(:, 2) - (1:length(d(:,2)))'/2;
phi(window:end) = conv(phi, ones(window,1)/window, 'valid');
phi(d(:,2) == (1:length(d(:,2)))') = max(phi);
phi(1: (alpha_0 + beta_0 - 1)) = [];
plot(phi);
for i =  1 : length(c)
    u = (40*c(i)+20)./(40+20*c(i));       
    LIP(:,i) = ((2 * u - 1) * (0:nT)' - phi) *  2;
    LIP(LIP(:,i) > 0,i) = 0;
    y = LIP(1:10,i);
    linCoeff = [(1:length(y))' * (1 + 0.5 * c(i)), ones(length(y),1)] \ y;
    Coeff(i) = linCoeff(1) * 1000;
end

figure;
plot( [0:nT]' * (1 + 0.5 * c'), LIP)
xlim([0,50]);
xlabel('Time', 'FontWeight', 'bold','FontSize',30);
ylabel('LIP Responses', 'FontWeight', 'bold','FontSize',30);
set(gca,  'LineWidth',2,...
    'FontWeight','bold');
set(gcf,'paperunits','inches');
set(gcf,'papersize',[18 12]);
set(gcf,'paperposition',[0,0,18,12]);

figure;
[~, RT] = modelRT(d,c, 0);
tStop = round(RT(:,1));
LIPlast = zeros(min(tStop), length(c));

for i = 1 : length(c)
    LIPlast(:,i)  = LIP(tStop(i)-min(tStop)+1:tStop(i),i);
end
plot([1:min(tStop)]' * (1 + 0.5 * c'), LIPlast(end:-1:1,:));

figure;
plot(c, Coeff,'-o','MarkerSize',10);
xlabel('Coherence','FontWeight', 'bold');
ylabel('Build up rate (Sp/s)','FontWeight', 'bold');
%xlim([c0(1), c0(end)]);

end

